<!DOCTYPE html>
<html>
  <head>
    <include file="./Public/html/_head.html"/>
  </head>
  
  <body ontouchstart>
    <include file="./Public/html/_refresh.html"/>
    <header class='demos-header'>
      <h1 class="demos-title">客观出题</h1>
    </header>

    <div class="weui_cells weui_cells_form">
      <div class="weui_cell">
        <div class="weui_cell_hd"><label class="weui_label">作业名称</label></div>
        <div class="weui_cell_bd weui_cell_primary" id="homeworkName">
          {$homeworkName|default="课后作业"}
          
          <select class="weui-select" name="class">
            <option selected="" value="1">选择班级</option>

            <option value="1">1班</option>
            <option value="2">2班</option>
          </select>
        </div>
      </div>
      <div class="weui_cell">
        <div class="weui_cell_hd"><label for="" class="weui_label">提交截止时间</label></div>
        <div class="weui_cell_bd weui_cell_primary">
          <input id="deadtime" class="weui_input" type="datetime-local" value="" placeholder="请选择截止时间">
        </div>
      </div>

      <div class="weui_cell">
        <div class="weui_cell_hd"><label for="" class="weui_label">互评截止时间</label></div>
        <div class="weui_cell_bd weui_cell_primary">
          <input id="deadtime" class="weui_input" type="datetime-local" value="" placeholder="请选择截止时间">
        </div>
      </div>

      
      <div class="weui_cell">
        <div class="weui_cell_hd"><label class="weui_label open-popup" id="suiji" data-target="#sj">随机出题</label></div>
      </div>

      <div class="weui_cell">
        <div class="weui_cell_hd"><label for="" class="weui_label open-popup" id="xuanze" data-target="#xz">选择出题</label></div>
      </div>

    <div id="sj" class='weui-popup-container popup-bottom'>
      <div class="weui-popup-modal">
        <div class="toolbar">
          <div class="toolbar-inner">
            <a href="javascript:;" class="picker-button close-popup">取消</a>
            <h1 class="title">章节</h1>
          </div>
        </div>
        <div class="modal-content">
          <div id="chapter">
            <for start="1" end="5">
              <div class="weui_cell">
                <div class="weui-cell">
                  <div class="weui-cell__bd">
                    <p>第{$i}章</p>
                  </div>
                  <div class="weui-cell__ft">
                    <div class="weui-count">
                      <a class="weui-count__btn weui-count__decrease"></a>
                      <input class="weui-count__number" type="number" value="1">
                      <a class="weui-count__btn weui-count__increase"></a>
                    </div>
                  </div>
                </div>
              </div>
            </for>
          </div>
          
        </div>
      </div>
    </div>

    </div>

    
    <div class="weui_btn_area">
      <a class="weui_btn weui_btn_primary" href="javascript:" id="submit">确定</a>
    </div>
    <div id="test"></div>
    <include file="./Public/html/_foot.html"/>
    <include file="./Public/html/_refreshJs.html"/>

    <script>
      $(function() {
        FastClick.attach(document.body);
      });
    </script>

    <script>
      var MAX = 9, MIN = 0;
      $('.weui-count__decrease').click(function (e) {
        var $input = $(e.currentTarget).parent().find('.weui-count__number');
        var number = parseInt($input.val() || "0") - 1
        if (number < MIN) number = MIN;
        $input.val(number)
      })
      $('.weui-count__increase').click(function (e) {
        var $input = $(e.currentTarget).parent().find('.weui-count__number');
        var number = parseInt($input.val() || "0") + 1
        if (number > MAX) number = MAX;
        $input.val(number)
      })

      $('.delete-swipeout').click(function () {
        $(this).parents('.weui-cell').remove()
      })
      $('.close-swipeout').click(function () {
        $(this).parents('.weui-cell').swipeout('close')
      })
    </script>
    <script>
      
        



        $(function(){
          var max = 200;
          $('#content').on('input', function(){
             var text = $(this).val();
             var len = text.length;
             $('#count').text(len);
             if(len > max){
               $(this).closest('.weui_cell').addClass('weui_cell_warn');
             }
             else{
               $(this).closest('.weui_cell').removeClass('weui_cell_warn');
             }
          });
        }),

        $("#submit").click(function() {

          var homeworkName = $('#homeworkName').html();
          var deadtime = $('#deadtime').val();
          var content = $('#content').val();
          if(deadtime == '') $.toptip('请选择截止时间');
          else if(content == '') $.toptip('请输入作业内容');
          else $.confirm('您确定要布置作业吗?','确定布置？',function(){
            $.showLoading('作业布置中');
            setTimeout(function(){
              //上传
              url = "{:U('homework_handAssign')}";
              data = {
                homeworkName:homeworkName,
                deadtime:deadtime,
                content:content
              }
              $.post(url,data,function(res){
                $("#test").html(res);
              })
              $.hideLoading();
              $.toast('作业布置成功!');
              $('#submit').hide();
            },1000);
          },function(){
            //取消操作
          });
        });

  </script>


  </body>
</html>